﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Kinect;
using System.Speech;


namespace PhysioAssist2Win
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {





        //JANELA
        public MainWindow()
        {
            InitializeComponent();

            //Ajusta posição e tamanho das janelas
            double width = System.Windows.SystemParameters.PrimaryScreenWidth;
            double height = System.Windows.SystemParameters.PrimaryScreenHeight;

            Win.Width = width;
            Win.Height = height;

            Win.Left = 0;
            Win.Top = 0;


            //pnlGeral
            pnlGeral.Width = width - 40;
            pnlGeral.Height = height - 40;
            pnlGeral.Margin = new Thickness(20, 20, 20, 20);





            //pnlEsq
            pnlEsq.Width = pnlGeral.Width * 0.25;
            pnlEsq.Height = pnlGeral.Height;

            //pnlCentro
            pnlCentro.Width = (pnlGeral.Width * 0.50) - 40;
            pnlCentro.Height = pnlGeral.Height;
            pnlCentro.Margin = new Thickness(20, 0, 20, 0);

            //pnlDir
            pnlDir.Width = pnlGeral.Width * 0.25;
            pnlDir.Height = pnlGeral.Height;




            //ESQUERDA
            pnlFotos.Width = pnlEsq.Width;
            pnlFotos.Height = (pnlEsq.Height * 0.25) - 15;
            pnlFotos.Margin = new Thickness(0, 0, 0, 20);

            pnlVideos.Width = pnlEsq.Width;
            pnlVideos.Height = (pnlEsq.Height * 0.25) - 15;
            pnlVideos.Margin = new Thickness(0, 0, 0, 20);

            pnlProfissionais.Width = pnlEsq.Width;
            pnlProfissionais.Height = (pnlEsq.Height * 0.25) - 15;
            pnlProfissionais.Margin = new Thickness(0, 0, 0, 20);

            pnlPacientes.Width = pnlEsq.Width;
            pnlPacientes.Height = (pnlEsq.Height * 0.25) - 15;




            //CENTRO
            pnlHospital.Width = pnlCentro.Width;
            pnlHospital.Height = (pnlCentro.Height * 0.5) - 10;
            pnlHospital.Margin = new Thickness(0, 0, 0, 20);

            pnlNoticias.Width = pnlCentro.Width;
            pnlNoticias.Height = (pnlCentro.Height * 0.5) - 10;




            //DIREITA
            pnlAgenda.Width = pnlCentro.Width;
            pnlAgenda.Height = (pnlCentro.Height * 0.5) - 10;
            pnlAgenda.Margin = new Thickness(0, 0, 0, 20);

            pnlAniversarios.Width = pnlCentro.Width;
            pnlAniversarios.Height = (pnlCentro.Height * 0.5) - 10;



            //Cabeçalhos
            Cabecalhos();



            //Noticias
            CarregaNoticias();




            //Anuncios
            CarregaAnuncios();




            //Agenda
            CarregaAgenda(DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year, 10);//HARDCODE




            //Aniversarios
            ListaAniversarios(DateTime.Now.Month);


        }







        //CABECALHOS
        private void Cabecalhos()
        {

            pnlFotos.Children.Add(Cabecalho("Fotos"));
            pnlVideos.Children.Add(Cabecalho("Vídeos"));
            pnlProfissionais.Children.Add(Cabecalho("Profissionais"));
            pnlPacientes.Children.Add(Cabecalho("Pacientes"));


            pnlHospital.Children.Add(Cabecalho("Hospital"));
            pnlNoticias.Children.Add(Cabecalho("Notícias"));


            pnlAgenda.Children.Add(Cabecalho("Agenda"));
            pnlAniversarios.Children.Add(Cabecalho("Aniversários"));

        }
        private Label Cabecalho(string texto)
        {
            Label lbl = new Label();
            lbl.Content = texto;
            lbl.FontSize = 40;
            lbl.Foreground = Brushes.White;

            return lbl;
        }






        //CLIQUES
        private void pnlAgenda_MouseDown(object sender, MouseButtonEventArgs e)
        {

            Agenda win = new Agenda();
            win.Show();

        }
        private void pnlAniversarios_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Aniversarios win = new Aniversarios();
            win.Show();
        }
        private void pnlPacientes_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Pacientes win = new Pacientes();
            win.Show();
        }
        private void pnlHospital_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Anuncios win = new Anuncios();
            win.Show();
        }
        private void pnlNoticias_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Noticias win = new Noticias();
            win.Show();
        }
        private void pnlFotos_MouseDown(object sender, MouseButtonEventArgs e)
        {
            FotosVideos win = new FotosVideos();
            win.Show();
        }
        private void pnlVideos_MouseDown(object sender, MouseButtonEventArgs e)
        {

            FotosVideos win = new FotosVideos();
            win.Show();
        }
        private void pnlProfissionais_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Profissionais win = new Profissionais();
            win.Show();
        }











        //NOTICIAS
        private void CarregaNoticias()
        {

            WS.WSSoapClient client = new WS.WSSoapClient();
            WS.Noticia[] lst = client.ListaNoticias();


            foreach (WS.Noticia noti in lst)
            {

                Label lbl = new Label();
                TextBlock txt = new TextBlock();

                lbl = new Label(); txt = new TextBlock();
                txt.Text = noti.data.ToShortDateString() + " - " + noti.fonte;
                txt.TextWrapping = TextWrapping.Wrap;
                lbl.Content = txt;
                lbl.FontSize = 15;
                lbl.FontWeight = FontWeights.Bold;
                lbl.Foreground = Brushes.White;
                pnlNoticias.Children.Add(lbl);


                lbl = new Label(); txt = new TextBlock();
                lbl.Margin = new Thickness(0, 0, 0, 30);
                txt.Text = noti.titulo;
                txt.TextWrapping = TextWrapping.Wrap;
                lbl.Content = txt;
                lbl.FontSize = 20;
                lbl.Foreground = Brushes.White;
                pnlNoticias.Children.Add(lbl);


            }



        }






        //HOSPITAL
        private void CarregaAnuncios()
        {

            WS.WSSoapClient client = new WS.WSSoapClient();
            WS.Anuncio[] lst = client.ListaAnuncios();


            foreach (WS.Anuncio anun in lst)
            {

                Label lbl = new Label();
                TextBlock txt = new TextBlock();

                lbl = new Label(); txt = new TextBlock();
                txt.Text = anun.data.ToShortDateString() + " - " + NomePessoa(anun.profissional);
                txt.TextWrapping = TextWrapping.Wrap;
                lbl.Content = txt;
                lbl.FontSize = 15;
                lbl.FontWeight = FontWeights.Bold;
                lbl.Foreground = Brushes.White;
                pnlHospital.Children.Add(lbl);


                lbl = new Label(); txt = new TextBlock();
                lbl.Margin = new Thickness(0, 0, 0, 30);
                txt.Text = anun.mensagem;
                txt.TextWrapping = TextWrapping.Wrap;
                lbl.Content = txt;
                lbl.FontSize = 20;
                lbl.Foreground = Brushes.White;
                pnlHospital.Children.Add(lbl);

            }



        }
        private string NomePessoa(int id)
        {

            WS.WSSoapClient client = new WS.WSSoapClient();
            WS.Profissional pro = client.GetProfissional(id);
            return pro.nome;


        }

















        //AGENDA
        private void CarregaAgenda(int dia, int mes, int ano, int profissional)
        {

            WS.WSSoapClient client = new WS.WSSoapClient();
            WS.Agenda[] lst = client.ListaAgenda(dia, mes, ano, profissional);

            foreach (WS.Agenda age in lst)
            {

                Label lbl = new Label();

                lbl.Content = age.dia + "/" + age.mes + "/" + age.ano + " " + age.hora + " - " + age.compromisso;
                lbl.FontSize = 20;
                lbl.Foreground = Brushes.White;
                pnlAgenda.Children.Add(lbl);

            }
        }














        //ANIVERSARIOS
        private void ListaAniversarios(int mes)
        {


            Label lbl = new Label();
            lbl.Content = "Coleguas do Hospital";
            lbl.FontWeight = FontWeights.Bold;
            lbl.FontSize = 15;
            lbl.Foreground = Brushes.White;
            pnlAniversarios.Children.Add(lbl);

            WS.WSSoapClient client = new WS.WSSoapClient();
            WS.Profissional[] lst = client.ListaAniversariosProfissional(mes);

            foreach (WS.Profissional pro in lst)
            {

                lbl = new Label();

                lbl.Content = pro.nascimento.Day + "/" + pro.nascimento.Month + " - " + pro.nome;
                lbl.FontSize = 20;
                lbl.Foreground = Brushes.White;

                pnlAniversarios.Children.Add(lbl);

            }




            lbl = new Label();
            lbl.Content = "\nPacientes";
            lbl.FontWeight = FontWeights.Bold;
            lbl.FontSize = 15;
            lbl.Foreground = Brushes.White;
            pnlAniversarios.Children.Add(lbl);

            client = new WS.WSSoapClient();
            WS.Paciente[] lst2 = client.ListaAniversariosPaciente(mes);

            foreach (WS.Paciente pac in lst2)
            {

                lbl = new Label();

                lbl.Content = pac.nascimento.Day + "/" + pac.nascimento.Month + " - " + pac.nome;
                lbl.FontSize = 20;
                lbl.Foreground = Brushes.White;

                pnlAniversarios.Children.Add(lbl);

            }

        }
        private string NomePessoal(int idpessoa, int tipo)
        {

            if (tipo == 1)
            {
                WS.WSSoapClient client = new WS.WSSoapClient();
                WS.Profissional pro = client.GetProfissional(idpessoa);
                return pro.nome;
            }
            if (tipo == 2)
            {
                WS.WSSoapClient client = new WS.WSSoapClient();
                WS.Paciente pac = client.GetPaciente(idpessoa);
                return pac.nome;
            }

            return "";

        }




    }
}
